﻿$(function () {
    var l = abp.localization.getResource('Rechargeable');

    var dataTable = $('#PorductPriceTable').DataTable(abp.libs.datatables.normalizeConfiguration({
        ajax: abp.libs.datatables.createAjax(rechargeable.products.productPrice.getList, function () { return { productId: $("#productId").val() }; }),
        processing: true,
        serverSide: true,
        paging: true,
        searching: false,
        autoWidth: false,
        scrollCollapse: true,
        columnDefs: [
            {
                rowAction: {
                    items:
                        [
                            {
                                text: l('Edit'),
                                action: function (data) {
                                }
                            },
                            {
                                text: "生成序列号",
                                action: function (data) {
                                    createSerialNumbersModal.open({ productId: $("#productId").val(), productPriceId: data.record.id });
                                    createSerialNumbersModal.onResult(function (data) {
                                        console.log(data);
                                        if (data.type === "abp-ajax-success")
                                            abp.message.info("成功生成序列号", "操作提示");
                                    });
                                }
                            }
                        ]
                }
            },
            { data: "desc" },
            { data: "money" },
            { data: "day" }
        ]
    }));
    var createSerialNumbersModal = new abp.ModalManager(abp.appPath + "Products/Prices/CreateSerialNumbers");
    var createModal = new abp.ModalManager(abp.appPath + "Products/Prices/CreateModal");
    createModal.onResult(function () {
        dataTable.ajax.reload();
    });
    $("#btnCreate").on("click", function (e) {
        e.preventDefault();
        createModal.open({ productId: $("#productId").val() });
    });


});